with GNAT.Regexp; use GNAT.Regexp;

with Ada.Strings.Bounded;

use Ada;

with Websites_Configuration; use Websites_Configuration;

--
-- separate HTTP headers from content
--

generic

   --
   -- String size limit for input arguments
   --

   Max_Input : Positive := HEAP_LIMIT;


package Headers_Parser is

   HTTP_Data_Empty   : exception;

   Headers_Not_Found : exception;

   Content_Not_Found : exception;

   --
   -- input and output argument type
   --

   subtype HTTP_String_Sub_Type is String

      with Dynamic_Predicate => HTTP_String_Sub_Type'Size <= Max_Input;

   --
   -- working storage for output
   --
   --    defined at package level to accommodate large strings
   --

   package String_Output_Type is new Strings.Bounded.Generic_Bounded_Length(

         Max => Max_Input );

   String_Output : String_Output_Type.Bounded_String;

   --
   -- Retrieve Headers only
   --
   --       without HTTP content
   --

   function Parse_Headers( HTTP_Data : in HTTP_String_Sub_Type )

         return String;


   --
   -- Retrieve HTTP content only
   --
   --       without Headers
   --

   function Parse_Content( HTTP_Data : in HTTP_String_Sub_Type )

         return String;


   --
   -- remove cached String divided by line feeds
   --

   procedure Clear;


private

   --
   -- Regular expression for HTTP response header
   --

   Header_RegEx : constant Regexp := GNAT.Regexp.Compile(

         "[A-Z]?.+[:]?.+[\r]?|" &

         "HTTP.+[\r]?|[\r]?",

         Case_Sensitive => true );

   --
   -- Divide HTTP String input by linefeed
   --
   --    return line count
   --
   --    String lines array as Slice Set stored at package level in order to
   --       accommodate large String data
   --

   function Lines_Present( HTTP_Data : in HTTP_String_Sub_Type )

         return Integer;


end Headers_Parser;